<?php

/*
	对话列表（工作人员）
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['tcp_status']=$this->tcp_status;
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$params['workerid']=0;
	$return['params']['isworker']=$_RQ['isworker'];
	if(!empty($_RQ['groupid'])){
		$params['groupid']=intval($_RQ['groupid']);
		$return['params']['groupid']=$_RQ['groupid'];
	}
	if(!empty($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	//对话名称
	if(!empty($_RQ['msg'])){
		$params['msg like']='%'.trim($_RQ['msg']).'%';
		$return['params']['msg']=$_RQ['msg'];
	}
	
	$orderby='id desc';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_ailiao_tcp',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($list as &$row){
		$row['member']=cfc('core')->member_show($row['mid']);
		$row['tomember']=cfc('core')->member_show($row['tomid']);
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'对话列表'),
		),
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'tomember','title'=>'对话会员','type'=>'member'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','op'=>'look','title'=>'查看对话'),
		)),
		'search'=>array(
			array('type'=>'radio','width'=>15,'name'=>'status','title'=>'对话状态','options'=>'tcp_status'),
			array('type'=>'string','width'=>15,'name'=>'msg','title'=>'对话内容'),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='look'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array(
			'msg'=>trim($post['msg']),
			'status'=>2,
		);
		$id=intval($post['id']);
		if(!$id){
			exi('请先选择对话！','error');
		}
		if(!$data['msg']){
			exi('请先填写对话处理结果！','error');
		}
		$post['is_worker']=1;
		$post['tcpid']=$post['id'];
		$this->model('kefu')->addchatlog($post);
		exi('提交成功！','','list');
	}
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择对话！','error');
	}
	$item=pdo_get('jy_ailiao_tcp',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$log=pdo_getall('jy_ailiao_tcplog',array('uniacid'=>$_SESSION['uniacid'],'tcpid'=>$item['id']));
	foreach($log as &$lv){
		$lv['image']=json_decode($lv['image'],true);
		$lv['member']=cfc('core')->member_show($lv['mid']);
	}
	$item['logs']=$log;
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'对话详情',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回列表'),
		),
		'look'=>array(
			array('type'=>'logs','name'=>'logs','jsname'=>'客服','title'=>'处理信息'),
		),
	);
	exi($return);
}